package com.suzhe.ymall.system.mapper;

import com.suzhe.ymall.system.pojo.SysResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 资源管理 Mapper 接口
 * </p>
 *
 * @author suzhe
 * @since 2019-06-07
 */
public interface SysResourceMapper extends BaseMapper<SysResource> {

    @Select("SELECT DISTINCT\n" +
            "\tsr.permission\n" +
            "FROM\n" +
            "\tsys_user_role ur \n" +
            "LEFT JOIN sys_role_resource rr ON ur.role_id = rr.role_id\n" +
            "LEFT JOIN sys_resource sr ON rr.resource_id = sr.id\n" +
            "WHERE\n" +
            "\tur.user_id = #{userId}\n" +
            "AND sr.type = #{type}")
    List<String> queryUserPerms(@Param("userId") Integer userId,@Param("type") Integer type);
}
